package com.glela.common.util;

public class OrderUtil {

	public static int INCREASE_SEED = 1;

	/**
	 * 获取自增长格式化前缀0的数字字符串
	 * 
	 * @param count
	 * @return
	 */
	public static String increaseSeed(int count) {
		String result = null;
		if (INCREASE_SEED > 99) {
			INCREASE_SEED = 1;
		}
		result = formatNum(INCREASE_SEED, count);
		INCREASE_SEED++;
		return result;
	}

	/**
	 * 格式化数字字符串-前缀0填充
	 * 
	 * @param num
	 * @param count
	 * @return
	 */
	public static String formatNum(int num, int count) {
		String result = num + "";
		int len = result.length();
		for (int i = 0; i < count - len; i++) {
			result = "0" + result;
		}
		return result;
	}

	/**
	 * 生成唯一订单编号
	 * 
	 * @return
	 */
	public static String getOrderSn() {
		String random = (int) (Math.random() * 999 + 1) + "";
		int len = random.length();
		for (int i = 0; i < 3 - len; i++) {
			random = "0" + random;
		}
		String result = null;
		result = System.currentTimeMillis() + random + increaseSeed(2);
		return result;
	}

}
